const { app, BrowserWindow } = require("electron");
// import { app, BrowserWindow } from "electron";
const path = require("path");
const WinState = require("electron-win-state").default;
const winState = new WinState({
  defaultWidth: 1000,
  defaultHeight: 800,
});

const createWindow = () => {
  const mainWindow = new BrowserWindow({
    ...winState.winOptions,
    // width: 1000,
    // height: 800,
    webPreferences: {
      nodeIntegration: true, //集成node
      //预加载
      preload: path.resolve(__dirname, "./preload/index.ts"), //必须是绝对路径，不能是相对路径
    },
    show: false,
  });

  mainWindow.loadURL("http://localhost:5173/");

  mainWindow.on("ready-to-show", () => {
    mainWindow.show();
  });

  //打开开发者工具
  mainWindow.webContents.openDevTools();

  //通过winState来记录管理窗口的大小和位置
  winState.manage(mainWindow);

  // 暂时关闭安全警告
  // process.env["ELECTRON_DISABLE_SECURITY_WARNINGS"] = "true";//没有生效，算了，还是直接使用配置CSP
};

app.whenReady().then(() => {
  createWindow();
});
